﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/sales/list_view.master" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        string n = Request.QueryString["h"] ?? "500";
        int h = int.Parse(n) - 100;

    }

    protected void page_Init(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["InvWhere"] = "1=0";

        }
    }



    #region search
    protected void Search_Click(object sender, EventArgs e)
    {
        string where = "";
        if (txt_no.Text.Trim() != "")
        {
            where = "JobOrderNo='" + SafeValue.SafeInt(txt_no.Text.Trim(), 0) + "'";
        }
        else if (this.txt_from.Value != null && this.txt_to.Value != null)
        {
            string dateFrom = this.txt_from.Date.ToString("yyyy-MM-dd");
            string dateTo = this.txt_to.Date.AddDays(1).ToString("yyyy-MM-dd");
            where = string.Format("JobDate>='{0}' and JobDate<'{1}'", dateFrom, dateTo);
        }

        Session["CfsImp"] = where;
        this.dsJobOrder.FilterExpression = where;
    }
    private string GetWhere(string where, string s)
    {
        if (where.Length > 0)
            where += " and " + s;
        else
            where = s;
        return where;
    }
    #endregion

    protected void grid_Order_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)
    {
    }
    protected void grid_Order_RowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
    {
    }
    protected void grid_Order_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
        ASPxLabel label = grid_Order.FindRowCellTemplateControl(e.VisibleIndex, null, "lab_InvoiceNo") as ASPxLabel;
        if (label == null || label.Text.Length < 3)
        {
        }
        else
        {
            e.Row.BackColor = System.Drawing.Color.LightGreen;
        }
    }

    protected void grid2_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.OpOrder));
        }
    }

    protected void grid2_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {
    }

    protected void grid2_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
    }

    protected void grid2_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
    }

    
    </script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style>
    div {font-size:10px;font-family:Verdana;}
    </style>
    <script type="text/javascript">
        var order = 0;
        function ViewOrder(n) {
            order = n;
            runApp("/Pages/Sales/EditPage/OrderView.aspx?no=" + n);
        }

        function ShowOrder(n) {
            if(n==0)
                parent.Popup('/Pages/Sales/EditPage/OrderEdit.aspx?no=' + 0, 'Service Order', 1000, 500);
             else
                 parent.Popup('/Pages/Sales/EditPage/OrderEdit.aspx?no=' + order, 'Service Order', 1000, 500);
         }
         function ShowInvoice(invN) {
             popubCtr.SetHeaderText('Invoice');
             popubCtr.SetContentUrl('EditPage/InvoiceEdit.aspx?InvN=' + invN);
             popubCtr.Show();
         }
         function PrintBill(invN) {
             parent.window.open("/rpt/printview.aspx?doc=50&no=" + invN);
         }

    </script>
</asp:Content>

<asp:Content ID="title1" ContentPlaceHolderID="Title1" Runat="Server">
<table width=100% cellpadding="4">
    <tr>
    <td align=left class="bb">
        Quick Navigation
    </td>
    <td align=right class="bb">
    </td>
    </tr>
</table>
</asp:Content>
<asp:Content ID="title2" ContentPlaceHolderID="Title2" Runat="Server">

<table width="100%">
           <tr>
                
                <td>
                    Date
                </td>
                <td>
                    <dxe:ASPxDateEdit ID="txt_from" Width="90" runat="server" EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                    </dxe:ASPxDateEdit>
                </td>
                <td>
                    To
                </td>
                <td>
                    <dxe:ASPxDateEdit ID="txt_to" Width="90" runat="server" EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                    </dxe:ASPxDateEdit>
                </td>
                <td>
                    <dxe:ASPxButton ID="ASPxButton1" Width="90" runat="server" Text="Search" OnClick="Search_Click">
                    </dxe:ASPxButton>
                </td>
                <td align=right width="100%">
                </td>
            </tr>
        </table>

</asp:Content>
<asp:Content ID="title3" ContentPlaceHolderID="Title3" Runat="Server">
<table width="100%">
           <tr>
                
                <td width="*" align="left">
                <dxe:ASPxButton ID="ASPxButton9" Width="110" runat="server" Text="New Order" AutoPostBack="False">
                            <ClientSideEvents Click="function(s, e) {
                    ShowOrder(0);
                        }" />
                        </dxe:ASPxButton>

                </td>
                
                <td align=right width="100">
                <dxe:ASPxButton ID="ASPxButton22" Width="90" runat="server" Text="Open" AutoPostBack="False">
                            <ClientSideEvents Click="function(s, e) {
                    ShowOrder(0);
                        }" />
                        </dxe:ASPxButton>
                </td>
            </tr>
        </table>

</asp:Content>

<asp:Content ID="Page1" ContentPlaceHolderID="Page1" Runat="Server">

     
        <table>
         <tr>
        <td colspan=2 align=left>
        <asp:RadioButton GroupName="time" Checked="true" ID="RadioButton0" runat="server" Text = "This Month" /><br /> 
        <asp:RadioButton GroupName="time" ID="RadioButton1" runat="server" Text = "Last Month" /><br /> 
        <asp:RadioButton GroupName="time" ID="RadioButton3" runat="server" Text = "Year to Date" /> <br />
        <asp:RadioButton GroupName="time" ID="RadioButton2" runat="server" Text = "" />
<asp:DropDownList id="ddl" 
           runat="server">
         <asp:ListItem>2010-01</asp:ListItem>
         <asp:ListItem>2010-02</asp:ListItem>
         <asp:ListItem>2010-03</asp:ListItem>
         <asp:ListItem>2010-04</asp:ListItem>
         <asp:ListItem>2010-05</asp:ListItem>
         <asp:ListItem>2010-06</asp:ListItem>
         <asp:ListItem>2010-07</asp:ListItem>
         <asp:ListItem>2010-08</asp:ListItem>
         <asp:ListItem>2010-09</asp:ListItem>
      </asp:DropDownList>

<br />
        </td>
        </tr>
        <tr>
        <td colspan=2>
        <hr />
        </td>
        </tr>
        <tr>
        <td colspan=2 align=left>
       <asp:RadioButton  GroupName="status" Checked="True" ID="RadioButton6" runat="server" Text = "All" /><br /> 
        <asp:RadioButton GroupName="status" ID="RadioButton4" runat="server" Text = "Open" /><br /> 
        <asp:RadioButton GroupName="status" ID="RadioButton5" runat="server" Text = "Closed" /><br />
        </td>
        </tr>
        <tr>
        <td colspan=2>
        <hr />
        </td>
        </tr>
        <tr>
        <td width=60>
                    Order No
                </td>
                <td>
                    <dxe:ASPxTextBox ID="txt_no" Width="70" runat="server" Text="">
                    </dxe:ASPxTextBox>
                </td>
                </tr>
        </table>

</asp:Content>
<asp:Content ID="Page2" ContentPlaceHolderID="Page2" Runat="Server">

               <wilson:DataSource ID="dsJobOrder" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpOrder" KeyMember="Oid" FilterExpression="1=1" />

<dxwgv:ASPxGridView ID="grid_Order" ClientInstanceName="grid_Order" runat="server"
            DataSourceID="dsJobOrder" Width="100%" KeyFieldName="Oid" AutoGenerateColumns="False"
             oncustomunboundcolumndata="grid_Order_CustomUnboundColumnData"  OnHtmlRowCreated="grid_Order_RowCreated" OnHtmlRowPrepared="grid_Order_HtmlRowPrepared" >
            <SettingsPager Mode="ShowAllRecords">
            </SettingsPager>
            <SettingsEditing Mode="EditForm" />
            <SettingsCustomizationWindow Enabled="True" />
            <SettingsBehavior AllowFocusedRow="true" />
            <ClientSideEvents FocusedRowChanged="function(s, e) { 
                                var tit=s.GetActiveTab().GetText();
                                if(tit.substring(0,5)=='Photo')
                                    grid_Order.PerformCallback('Photo');
                                    }" />
            <Columns>
                
                <dxwgv:GridViewDataTextColumn Caption="Order No" FieldName="JobNo" VisibleIndex="1" SortIndex="0" SortOrder="Descending">
                    <DataItemTemplate>
                        <a onclick='ViewOrder("<%# Eval("JobNo") %>");'><%# Eval("JobNo") %></a>
                    </DataItemTemplate>
            
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Status" FieldName="JobStatus" VisibleIndex="2">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataDateColumn Caption="Date" FieldName="JobDate" PropertiesDateEdit-DisplayFormatString="dd/MM/yyyy"   VisibleIndex="3">
             
                </dxwgv:GridViewDataDateColumn>
                <dxwgv:GridViewDataTextColumn Caption="Customer" Width="150" FieldName="CustName" VisibleIndex="3">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Technician" Width="100" FieldName="Tehnician" VisibleIndex="5">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Type" FieldName="JobType" VisibleIndex="6">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataSpinEditColumn  Caption="Total Amount" FieldName="Amount"  PropertiesSpinEdit-DisplayFormatString="{0:#,##0.00}"  VisibleIndex="7">
                </dxwgv:GridViewDataSpinEditColumn>
                
               
            </Columns>
        </dxwgv:ASPxGridView>

        

</asp:Content>
<asp:Content ID="Page3" ContentPlaceHolderID="Page3" Runat="Server">
</asp:Content>

